home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / graphics / anim / displayanim1.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  7KB  |  332 lines

  1.  
  2. /* displayanim1.c
  3.  *    library of routines to support and aid the implementation
  4.  *    of multi-buffered graphics on the amiga.
  5.  *
  6.  *    written by Gary Bonham
  7.  *               Sparta, Inc.
  8.  *               Laguna Hills, Ca
  9.  *
  10.  */
  11.  
  12. #include "intuall.h"
  13. #include "libraries/dos.h"
  14. #include "libraries/dosextens.h"
  15. #include "dbview.h"
  16. #include "functions.h"
  17.  
  18. /* #define DEBUG */
  19.  
  20. int Pop,vmode,Active_View,Display_View,Master_View,No_Views,dy,dy2;
  21. int Verbose;
  22.  
  23. struct DBView DBView[10];
  24. extern struct GfxBase *GfxBase;
  25. extern int ScreenNTSC;
  26.  
  27. int SaveWW,SaveHH;
  28.  
  29. struct View v,*graphics;
  30. struct ViewPort vp,vp2;
  31. struct RasInfo ri,ri2;
  32. struct RastPort rp;
  33.  
  34. extern int Ddx,Ddy;
  35. extern struct Preferences *Prefs;
  36. struct ColorMap *cm[4];
  37. UWORD *col;
  38. struct ColorMap *GetColorMap();
  39. extern BYTE *SavePlanes[2];
  40.  
  41. /* ==================================== */
  42.  
  43. DBOpenGraphics(nbufs,ww,hhh,dd)
  44. int nbufs,ww,hhh,dd;
  45. {
  46.    int i,j,hh;
  47.    int DH,DW;
  48.  
  49.    hh = hhh * dd;
  50.    graphics = GfxBase->ActiView;
  51.  
  52.    No_Views = nbufs;
  53.    vmode = NULL;
  54.  
  55.    InitView(&v);
  56.    InitVPort(&vp);
  57.  
  58.    v.DxOffset += Ddx + Prefs->ViewXOffset;
  59.    v.DyOffset += Ddy + Prefs->ViewYOffset;
  60.  
  61.    DH = hhh;
  62.    if (DH >= 400) {
  63.       if (ScreenNTSC) DH = (DH - 400) / 2;
  64.       else DH = (DH - 512) / 2;
  65.    }
  66.    else {
  67.       if (ScreenNTSC) DH = (DH - 200) / 2;
  68.       else DH = (DH - 256) / 2;
  69.    }
  70.    DW = ww;
  71.    if (DW >= 640) DW = (DW - 640) / 2;
  72.    else           DW = (DW - 320) / 2;
  73.  
  74.    vp.DxOffset = -DW;
  75.    vp.DyOffset = -DH;
  76.  
  77.    ri.RxOffset = 0;
  78.    ri.RyOffset = 0;
  79.    ri.Next = NULL;
  80.  
  81.    vp.RasInfo = &ri;
  82.    cm[0] = GetColorMap(32L);
  83.    cm[1] = GetColorMap(32L);
  84.    for (i=0;i<2;i++) {
  85.       DBView[i].plane0 = 0;
  86.       DBView[i].plane1 = 0;
  87.       DBView[i].type = 0;
  88.       DBView[i].LOFCprList = 0;
  89.       DBView[i].SHFCprList = 0;
  90.       for (j=0;j<32;j++)
  91.          DBView[i].colorMap[j] = 0;
  92.    }
  93.    for (i=0;i<nbufs;i++) {
  94.       DBView[i].plane0 = (PLANEPTR)SavePlanes[i];
  95.       DBView[i].BitMap.Planes[0] = DBView[i].plane0;
  96.       DBView[i].planewidth = ww;
  97.       DBView[i].planeheight = hh;
  98.       DBView[i].type = 1;
  99.    }
  100.    if (DBView[nbufs-1].plane0 == NULL) GoodBye("Not enough memory for bitmaps");
  101.  
  102.    SaveWW = ww;
  103.    SaveHH = hh;
  104.  
  105.    InitRastPort(&rp);
  106.  
  107.    DBDraw(0);
  108.    DBClear(ww,hhh,dd); /* start on black frame - view 0 */
  109.    DBDisplay(0);
  110.    DBDraw(1);
  111.    DBClear(ww,hhh,dd); /* init Active_View also */
  112.    return(0);
  113. }
  114.  
  115. /* specify view for draws (output bitmap)
  116.  */
  117.  
  118. DBDraw(i)
  119. int i;
  120. {
  121.    rp.BitMap = &DBView[i].BitMap;
  122.    Active_View = i;
  123.    return(0);
  124. }
  125.  
  126. DBCloseGraphics()
  127. {
  128.    int i;
  129.  
  130.    if (graphics) {
  131.       LoadView(graphics); /* put back the old view */
  132.       graphics = NULL;
  133.  
  134.       for (i=0;i<2;i++) FreeColorMap(cm[i]);
  135.  
  136.       FreeVPortCopLists(&vp);
  137.       for (i=0;i<2;i++) {
  138.          if (DBView[i].LOFCprList) FreeCprList(DBView[i].LOFCprList);
  139.          if (DBView[i].SHFCprList) FreeCprList(DBView[i].SHFCprList);
  140.       }
  141.    }
  142.    return(0);
  143. }
  144.  
  145. DBCloseBuffer(i)
  146. int i;
  147. {
  148.    if (DBView[i].type == 1) {
  149.       if (DBView[i].plane0) FreeRaster(DBView[i].plane0
  150.          ,(long)SaveWW,(long)SaveHH);
  151.    }
  152.    DBView[i].type = 0;
  153.    return(0);
  154. }
  155.  
  156. /* build coplist for given view
  157.  */
  158.  
  159. MakeDBView()
  160. {
  161.    int DH,DW;
  162.    int i,j;
  163.  
  164.    i = Active_View;
  165.    if (DBView[i].LOFCprList) FreeCprList(DBView[i].LOFCprList);
  166.    if (DBView[i].SHFCprList) FreeCprList(DBView[i].SHFCprList);
  167.    FreeVPortCopLists(&vp);
  168.  
  169.    InitView(&v);
  170.    InitVPort(&vp);
  171.  
  172.    DH = DBView[i].DHeight;
  173.    if (DH >= 400) {
  174.       if (ScreenNTSC) DH = (DH - 400) / 2;
  175.       else DH = (DH - 512) / 2;
  176.    }
  177.    else {
  178.       if (ScreenNTSC) DH = (DH - 200) / 2;
  179.       else DH = (DH - 256) / 2;
  180.    }
  181.    DW = DBView[i].DWidth;
  182.    if (DW >= 640) DW = (DW - 640) / 2;
  183.    else           DW = (DW - 320) / 2;
  184.  
  185.    vp.DxOffset = -DW;
  186.    vp.DyOffset = -DH;
  187.  
  188.    v.ViewPort = &vp;
  189.    v.Modes |= vmode;
  190.    v.DxOffset += Ddx + Prefs->ViewXOffset;
  191.    v.DyOffset += Ddy + Prefs->ViewYOffset;
  192.  
  193.    v.LOFCprList = 0;
  194.    v.SHFCprList = 0;
  195.  
  196.    vp.DWidth = DBView[i].DWidth;
  197.    vp.DHeight = DBView[i].DHeight;
  198.  
  199.    vp.DxOffset += DBView[i].DxOffset;
  200.    vp.DyOffset += DBView[i].DyOffset;
  201.    vp.Modes = DBView[i].Modes;
  202.    if (vp.Modes & LACE) v.Modes |= LACE;
  203.    if (vp.Modes & HAM) v.Modes |= HAM;
  204.    vp.RasInfo = &ri;
  205.    col = (UWORD *)cm[i]->ColorTable;
  206.    for (j=0;j<32;j++) {
  207.       *col++ = DBView[i].colorMap[j];
  208.    }
  209.    vp.ColorMap = cm[i];
  210.    ri.BitMap = &DBView[i].BitMap;
  211.    ri.RxOffset = 0;
  212.    ri.RyOffset = 0;
  213.    ri.Next = NULL;
  214.  
  215.    MakeVPort(&v,&vp);
  216.    MrgCop(&v);
  217.    DBView[i].LOFCprList = v.LOFCprList;
  218.    DBView[i].SHFCprList = v.SHFCprList;
  219.    return(0);
  220. }
  221.  
  222. /*  Display specified view
  223.  */
  224.  
  225. DBDisplay(i)
  226. int i;
  227. {
  228.    int j;
  229.  
  230.    j = Active_View;
  231.    Active_View = i;
  232.    MakeDBView();
  233.    LoadView(&v);
  234.    WaitBlit();
  235.    WaitTOF();
  236.    Display_View = i;
  237.    DBDraw(j); /* makes Active_View = j */
  238.    return(0);
  239. }
  240.  
  241. /* display Active_View
  242.  */
  243.  
  244. DBflip()
  245. {
  246.    int i;
  247.  
  248.    i = Display_View;
  249.    DBDisplay(Active_View);
  250.    DBDraw(i); /* set Active_View to prev. Display_View */
  251.    return(0);
  252. }
  253.  
  254.  
  255. /*  clear a view to color 0 (black), specified resolution and depth
  256.  */
  257.  
  258. DBClear(iwidth,iheight,idepth)
  259. int iwidth,iheight,idepth;
  260. {
  261.    long plsize,iview;
  262.    long i,j;
  263.    LONG *p;
  264.  
  265.    iview = Active_View;
  266.    InitBitMap(&DBView[iview].BitMap,(long)idepth,(long)iwidth,(long)iheight);
  267.    DBView[iview].DWidth = iwidth;
  268.    DBView[iview].DHeight = iheight;
  269.    DBView[iview].Depth = idepth;
  270.    DBView[iview].DxOffset = 0;
  271.    DBView[iview].DyOffset = 0;
  272.    if (iwidth >= 640) DBView[iview].Modes = HIRES;
  273.    else DBView[iview].Modes = NULL;
  274.    if (iheight >= 400) DBView[iview].Modes |= LACE;
  275.    if (idepth == 6)   DBView[iview].Modes |= EXTRA_HALFBRITE;
  276.    DBView[iview].nColorRegs = 1<<idepth;
  277.    if (idepth >= 6) DBView[iview].nColorRegs = 32;
  278.    DBView[iview].colorMap[0] = 0;
  279.    plsize = (long)RowBytes(iwidth) * (long)iheight;
  280.    j = (plsize * (long)idepth) >>2;
  281.    p = (LONG *)DBView[iview].plane0;
  282.    for (i=0;i<j;i++) *(p + i) = 0; /* BltClear but will work in fast ram */
  283.    for (i=0;i<idepth;i++)
  284.       DBView[iview].BitMap.Planes[i]
  285.           = DBView[iview].plane0 + plsize * (long)i;
  286.    return(0);
  287. }
  288.  
  289. DBCopy(dview,sview)
  290. WORD sview,dview;
  291. {
  292.    LONG nl,i,*ss,*dd;
  293.  
  294.    DBInitView(dview,sview);
  295.  
  296.    nl =    DBView[sview].BitMap.Rows
  297.         * (DBView[sview].BitMap.BytesPerRow>>2)
  298.         *  DBView[sview].BitMap.Depth;
  299.    ss = (LONG *)DBView[sview].plane0;
  300.    dd = (LONG *)DBView[dview].plane0;
  301.  
  302.    for (i=0;i<nl;i++) {
  303.       *dd = *ss;
  304.       dd++;
  305.       ss++;
  306.    }
  307.    return(0);
  308. }
  309.  
  310. DBInitView(View,oldview)
  311. WORD View,oldview;
  312. {
  313.    long ia,ip;
  314.    for (ia=0;ia<32;ia++) DBView[View].colorMap[ia] =
  315.                                  DBView[oldview].colorMap[ia];
  316.    DBView[View].DWidth     = DBView[oldview].DWidth;
  317.    DBView[View].DHeight    = DBView[oldview].DHeight;
  318.    DBView[View].Depth      = DBView[oldview].Depth;
  319.    DBView[View].DxOffset   = DBView[oldview].DxOffset;
  320.    DBView[View].DyOffset   = DBView[oldview].DyOffset;
  321.    DBView[View].nColorRegs = DBView[oldview].nColorRegs;
  322.    DBView[View].Modes      = DBView[oldview].Modes;
  323.    InitBitMap(&DBView[View].BitMap,(long)DBView[View].Depth
  324.       ,(long)DBView[View].DWidth,(long)DBView[View].DHeight);
  325.    ia = (long)(DBView[oldview].DWidth>>3) * (long)DBView[oldview].DHeight;
  326.    for (ip=0;ip<DBView[oldview].Depth;ip++) {
  327.       DBView[View].BitMap.Planes[ip] = DBView[View].plane0 + ia * ip;
  328.    }
  329.    return(0);
  330. }
  331.  
  332.